package business;

import repository.AddressRepository;
import classes.Address;
import classes.City;
import classes.District;
import classes.Iterator;
import exceptions.RepositoryException;

public class AddressBusiness
{
	private AddressRepository repository;
	
	public AddressBusiness() throws RepositoryException
	{
		this.repository = AddressRepository.getInstance();
	}
	
	public void add( Address address ) throws RepositoryException
	{
		if( address != null )
		{
			repository.add( address );
		}
		else
		{
			throw new NullPointerException();
		}
	}
	
	public void edit( Address address ) throws RepositoryException
	{
		if( address != null )
		{
			repository.edit( address );
		}
		else
		{
			throw new NullPointerException();
		}
	}
	
	public Iterator< Address > find( Address address ) throws RepositoryException
	{
		Iterator< Address > ret;
		
		if( address != null )
		{
			ret = repository.find( address );
		}
		else
		{
			throw new NullPointerException();
		}
		
		return ret;
		
	}
	
	public Iterator< District > findDistrict( District district ) throws RepositoryException
	{
		Iterator< District > ret;
		
		if( district != null )
		{
			ret = repository.findDistrict( district );
		}
		else
		{
			throw new NullPointerException();
		}
		
		return ret;
	}
	
	public int findId( Address address ) throws RepositoryException
	{
		int ret;
		
		if( address != null )
		{
			ret = repository.findId( address );
		}
		else
		{
			throw new NullPointerException();
		}
		
		return ret;
		
	}
	
	public Address get( int id ) throws RepositoryException
	{
		return repository.get( id );
	}
	
	public Iterator< Address > getIterator() throws RepositoryException
	{
		return repository.getIterator();
	}
	
	public Iterator< City > getCityIterator() throws RepositoryException
	{
		return repository.getCityIterator();
	}
	
	public void remove( int id ) throws RepositoryException
	{
		repository.remove( id );
	}
	
	public int size() throws RepositoryException
	{
		return repository.size();
	}
}
